<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>title</title>
    </h:head>
    <h:body>

        <ui:composition template="../../templates/master.xhtml">

            <ui:define name="content">


                <p:panel id="panel" header="Edit Post">
                    <p:messages id="messages" />
                    <h:panelGrid columns="3" >

                        <h:outputText value="Name"/>
                        <p:inputText id="name" value="#{postsController.selected.name}" required="true">
                            <f:validateLength for="name" maximum="255"/>
                            <f:validateRequired for="name" />
                        </p:inputText>
                        <p:message for="name"/>
                        
                        <h:outputText value="Summary"/>
                        <p:inputText id="summary" value="#{postsController.selected.summary}">
                        </p:inputText>
                        <p:message for="summary"/>
                        
                        <h:outputText   value="Content" />
                        <p:inputTextarea id="content" value="#{postsController.selected.content}" required="true">
                        </p:inputTextarea>
                        <p:message for="content"/>
                      
                        <h:outputText value="Category Post" />
                        <p:selectOneMenu id="catePost" effect="fold" value="#{postsController.selected.categoryPostID}">
                            <f:selectItems value="#{postCategoresController.itemsAvailableSelectOne}" var="post" 
                                           itemLabel="#{post.label}" itemValue="#{post.value}"/>
                        </p:selectOneMenu>
                        <p:message for="catePost"></p:message>
                       
                        <h:outputText value="Post Image"/>
                        <h:form enctype="multipart/form-data"> 
                            <p:fileUpload id="postImg"   
                                          mode="advanced"   
                                          auto="true"
                                          fileUploadListener="#{postsController.handleFileUpload}"
                                          update="categoryIconMessage" 
                                          oncomplete="uploadPostIconComplete()"
                                          sizeLimit="10000000"   
                                          allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>  
                            <p:growl id="categoryIconMessage" showDetail="true"/>  
                        </h:form>
                    </h:panelGrid>
                    <f:facet name="footer">
                        <table width="100%">
                            <tr>
                                <td width="30%">
                                    <p:commandButton ajax="false" update="messages" value="Save" icon="ui-icon-check" action="#{postsController.update()}"/>
                                </td>
                                <td align="right"> 
                                    <p:commandButton ajax="false" immediate="true" icon="ui-icon-add" action="#{postsController.prepareCreate()}" value="Create"/> 
                                    <p:commandButton ajax="false" immediate="true" icon="ui-icon-list" action="#{postsController.prepareList()}" value="List"/>
                                </td>
                            </tr>
                        </table>

                    </f:facet>
                </p:panel>

            </ui:define>
        </ui:composition>
    </h:body>
</html>
